# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Yejun Yang <yejunx AT gmail DOT com>
# Contributor: Michal Krenek <mikos@sg1.cz>

pkgname=libsrtp
pkgver=2.4.0
pkgrel=1
epoch=1
pkgdesc="Library for SRTP (Secure Realtime Transport Protocol)"
url="https://github.com/cisco/libsrtp"
arch=(x86_64)
license=(BSD)
depends=(nss)
makedepends=(git meson libpcap doxygen)
checkdepends=(procps-ng)
provides=("libsrtp${pkgver%%.*}.so")
_commit=063e3652feae15ec48614a91d32757781e6251b4  # tags/v2.4.0
source=("git+https://github.com/cisco/libsrtp#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd $pkgname

  # Fixup pkgver: There are tags like v1.5.4 but also "moving" tags like v1 and v1.5
  git tag | grep -Pv '^v\d+.\d+.\d+$' | xargs git tag -d
}

build() {
  arch-meson $pkgname build \
    --buildtype release \
    -D crypto-library=nss \
    -D crypto-library-kdf=disabled
  meson compile -C build
  meson compile -C build doc
}

check() {
  meson test -C build --print-errorlogs
}

package() {
  meson install -C build --destdir "$pkgdir"

  mkdir -p "$pkgdir/usr/share/doc"
  cp -a build/html "$pkgdir/usr/share/doc/$pkgname"

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 $pkgname/LICENSE
}
